package com.ruoyi.patrol.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.patrol.domain.PtArea;
import com.ruoyi.patrol.service.IPtAreaService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 片区信息Controller
 * 
 * @author linan
 * @date 2024-02-03
 */
@RestController
@RequestMapping("/resource/area")
public class PtAreaController extends BaseController
{
    @Autowired
    private IPtAreaService ptAreaService;

    /**
     * 查询片区信息列表
     */
    @PreAuthorize("@ss.hasPermi('resource:area:list')")
    @GetMapping("/list")
    public TableDataInfo list(PtArea ptArea)
    {
        startPage();
        List<PtArea> list = ptAreaService.selectPtAreaList(ptArea);
        return getDataTable(list);
    }

    /**
     * 导出片区信息列表
     */
    @PreAuthorize("@ss.hasPermi('resource:area:export')")
    @Log(title = "片区信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PtArea ptArea)
    {
        List<PtArea> list = ptAreaService.selectPtAreaList(ptArea);
        ExcelUtil<PtArea> util = new ExcelUtil<PtArea>(PtArea.class);
        util.exportExcel(response, list, "片区信息数据");
    }

    /**
     * 获取片区信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('resource:area:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(ptAreaService.selectPtAreaById(id));
    }

    /**
     * 新增片区信息
     */
    @PreAuthorize("@ss.hasPermi('resource:area:add')")
    @Log(title = "片区信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PtArea ptArea)
    {
        return toAjax(ptAreaService.insertPtArea(ptArea));
    }

    /**
     * 修改片区信息
     */
    @PreAuthorize("@ss.hasPermi('resource:area:edit')")
    @Log(title = "片区信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PtArea ptArea)
    {
        return toAjax(ptAreaService.updatePtArea(ptArea));
    }

    /**
     * 删除片区信息
     */
    @PreAuthorize("@ss.hasPermi('resource:area:remove')")
    @Log(title = "片区信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(ptAreaService.deletePtAreaByIds(ids));
    }
}
